RANDOM

Section: MINTLIB LIBRARY FUNCTIONS (3)
Updated: 3 March 1993
Index Return to Main Contents
 

NAME

random, srandom, initstate, setstate - improved random number generator; routines for changing generators  

SYNOPSIS

#include <unistd.h>

long random(void);

void srandom (unsigned int seed);

char * initstate (unsigned int seed, char *arg_state, int n);

char * setstate (char *arg_state);
 

DESCRIPTION

random is a good random number generator returning pseudo- random numbers in the range from 0 to 2^31 - 1. The random number generator has a very large period. random/srandom have (almost) the same calling sequence and initialization properties as rand/srand. The difference is that rand produces a much less random sequence, while all the bits generated by random are useable. The initstate routine allows a state array, passed in an argument, to be initialized for future use. The size of the state array (in bytes) is used by initstate to decide how sophisticated a random number generator it should use - the more state, the better the random numbers will be. Good values for the amount of state information are 32, 64, 128 and 256 bytes. The seed for the initialization (which specifies a starting point for the random number sequence, and provides for restarting at the same point) is also an argument. initstate returns a pointer to the previous state information array. Once a state array has been initialized, the setstate routine provides for rapid switching between states. setstate returns a pointer to the previous state array; its argument state array is used for further random number generation until the next call to initstate or setstate. Once a state array has been initialized, it may be restarted at a different point either by calling initstate (with the desired seed, the state array, and its size) or by calling both setstate (with the state array) and srandom (with the desired seed). The advantage of calling both setstate and srandom is that the size of the state array does not have to be remembered after it is initialized.  

SEE ALSO

rand(3), srand(3)  

NOTES

See the source file (random.c) for complete information and comments on the workings of the random number generator. random is slower than rand.
 

Index

NAME
SYNOPSIS
DESCRIPTION
SEE ALSO
NOTES

This document was created by man2html, using the manual pages.
Time: 11:15:05 GMT, June 22, 2025